package org.familysearch.fsapi.gwt.server.dao.rest.parsers;

import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.familysearch.fsapi.gwt.common.client.entities.Person;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class PersonSAXParser extends DefaultHandler {

	private String tempVal = "";
	private Person person = new Person();
	private ArrayList<Person> persons = new ArrayList<Person>();
	private Logger log;
	
	public PersonSAXParser()
	{	
		log = Logger.getLogger(this.getClass().getName());
	}
	
	public void startElement(
			String uri, 
			String localName, 
			String qName,
			Attributes attributes) throws SAXException {

			log.debug("startElement="+qName);
			

	}

	public void characters(char[] ch, int start, int length) throws SAXException {
		tempVal = new String(ch,start,length);
		log.debug("tempVal="+tempVal);
	}

	public void endElement(String uri, String localName,
			String qName) throws SAXException {

			log.debug("endElement="+qName);
						
			// the fullText has the whole name
			if(qName.equalsIgnoreCase("fullText")) {
				person.setFullText(tempVal);
			}
			
			//TODO: parse the rest of Person here, adding other data as necessary
	}

	public ArrayList<Person> getPersons() {
		return persons;
	}

	public void setPersons(ArrayList<Person> persons) {
		this.persons = persons;
	}

	public Person getPerson() {
		return person;
	}
	

}
